//按钮事件新增或编辑
var BF6941_type = "";
//其他页面传到本页面参数
var BF6941_param = {};
//暂时没用
var BF6941_validate = "";

/*定义下拉框集合定义*/
/*declare select options begin*/

/*declare select options end*/

//主从表传递参数
function BF6941_param_set(){
	/*Main Subsuv Table Param Begin*/
	if(BF6941_param.hasOwnProperty("PID"))
        $("#BF6941_PID").val(BF6941_param["PID"]);
	if(BF6941_param.hasOwnProperty("PID_cn_name"))
        $("#BF6941_PID_cn_name").val(BF6941_param["PID_cn_name"]);
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function BF6941_t_tree_biz_start(inputdata) {
	BF6941_param = inputdata;
	layer.close(ly_index);
	BF6941_param_set();
    /*biz begin*/

    BF6941_init_t_tree();
    /*biz end*/
}

/*biz step begin*/

/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

/*find qry fun end*/

/*页面结束*/
function BF6941_page_end(){
	if(BF6941_param["type"] == "edit"){
		BF6941_get_edit_info();
	}
}

//页面初始化方法
function BF6941_init_t_tree() {
	//type = getUrlParam("type");
	BF6941_param_set();
	if(BF6941_param["type"] == "add"){
//		$("#BF6941_main_id").parent().parent().parent().hide();
		
		/*父页面查询条件参数传递至子页面并赋值*/
		/*Get Find Select param bgein*/
		
		/*Get Find Select param end*/	
	}
	else if(BF6941_param["type"] == "edit"){
	
	}
	
	//表单验证
	BF6941_checkFormInput();
	/*时间格式初始化*/
	/*form datetime init begin*/
	
    /*form datetime init end*/
	
	BF6941_page_end();
}

//提交表单数据
function BF6941_SubmitForm(){
	if(BF6941_param["type"] == "add"){
		var inputdata = {
				"param_name": "N01_ins_t_tree",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": $("#BF6941_PID").val()
                ,"param_value2": s_encode($("#BF6941_TEXT").val())
                ,"param_value3": s_encode($("#BF6941_S_DESC").val())
				
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "BF6941_get_N01_ins_t_tree");
	}
	else if(BF6941_param["type"] == "edit"){
		var inputdata = {
				"param_name": "N01_upd_t_tree",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": $("#BF6941_PID").val()
                ,"param_value2": s_encode($("#BF6941_TEXT").val())
                ,"param_value3": s_encode($("#BF6941_S_DESC").val())
                ,"param_value4": $("#BF6941_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "BF6941_get_N01_upd_t_tree");
	}
}

//vue回调
function BF6941_t_tree_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
	
	/*get find subvue end*/
}

//for表单提交
$("#BF6941_save_t_tree_Edit").click(function () {
	$("form[name='BF6941_DataModal']").submit();
})

/*修改数据*/
function BF6941_get_N01_upd_t_tree(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_t_tree) == true)
	{
		swal("修改数据成功!", "", "success");
		AF6941_t_tree_query();
		BF6941_clear_validate();
		layer.close(BF6941_param["ly_index"]);
	}
}

/*添加数据*/
function BF6941_get_N01_ins_t_tree(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_t_tree) == true)
	{
		swal("添加数据成功!", "", "success");
		AF6941_t_tree_query();
		BF6941_clear_validate();
		layer.close(BF6941_param["ly_index"]);
	}
}

//取消编辑
$("#BF6941_cancel_t_tree_Edit").click(function () {
	layer.close(BF6941_param["ly_index"]);
	BF6941_clear_validate();
	$("[id^='BF6941_div']").hide();
})

//清除查找框
function BF6941_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function BF6941_clear_validate(){
	$("#BF6941_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#BF6941_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#BF6941_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function BF6941_clear_edit_info(){
	var inputs = $("#BF6941_DataModal").find('input');
	var selects = $("#BF6941_DataModal").find("select");
	var textareas = $("#BF6941_DataModal").find('textarea');
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	/*清除输入框验证信息*/
	/*input validate clear begin*/
	
	/*input validate clear end*/
	BF6941_init_t_tree();
}

//页面输入框赋值
function BF6941_get_edit_info(){
	var rowData = $("#AF6941_t_tree_Events").bootstrapTable('getData')[AF6941_select_t_tree_rowId];
	var inputs = $("#BF6941_DataModal").find('input');
	var selects = $("#BF6941_DataModal").find("select");
	var textareas = $("#BF6941_DataModal").find('textarea');
	
	//通用子页面输入框赋值
	Com_edit_info(rowData,inputs,selects,textareas,"AF6941","BF6941");
}

//form验证
function BF6941_checkFormInput() {
    BF6941_validate = $("#BF6941_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            BF6941_MAIN_ID: {}
            ,BF6941_LOGIN_ID: {maxlength:50}
            ,BF6941_LOGIN_PWD: {maxlength:50}
            ,BF6941_NICK_NAME: {maxlength:20}
            ,BF6941_S_SORT: {digits: true,required : true,maxlength:10}
            ,BF6941_S_STATE: {}
            ,BF6941_CREATE_DATE: {date: true,required : true,maxlength:19}
            ,BF6941_S_DESC: {maxlength:500}
			
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            BF6941_MAIN_ID: {}
            ,BF6941_LOGIN_ID: {maxlength:"长度不能超过50"}
            ,BF6941_LOGIN_PWD: {maxlength:"长度不能超过50"}
            ,BF6941_NICK_NAME: {maxlength:"长度不能超过20"}
            ,BF6941_S_SORT: {digits: "必须输入整数",required : "必须输入整数",maxlength:"长度不能超过10" }
            ,BF6941_S_STATE: {}
            ,BF6941_CREATE_DATE: {date: "必须输入正确格式的日期",required : "必须输入正确格式的日期",maxlength:"长度不能超过19"}
            ,BF6941_S_DESC: {maxlength:"长度不能超过500"}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	BF6941_SubmitForm();
        	return false;
        }
    })
}